I've made a rather startling discovery: there seems to be a loss of DXL context for a 'realized' dialog that is not then 'show'n, when the DXL ends naturally (running out of code to execute) and doesn't end explicitely. Read and run the code below. Selecting the 1st 4 options (that explicitely end the DXL) allow the realized dialog to work correctly, but the last option (allowing the code to run out of things to do) causes the realized dialog to lose its DXL context resulting in "undefined" global variable access.
// Special Ending
/* This DXL demonstrates the corruption of the DXL context for 'realized' but not 'shown' dialogs.
When a DXL 'realizes' a dialog and then the execution ends because it runs out of lines
of code, and doesn't end because of some explicit event, then any 'realized'
dialog remains shown but is stripped of its context, and any global variables
it accesses generates "unassigned variable reference" errors.
An 'event' seems to be any of these:
halt
show(dialog)
error(message)
generating a DXL error
Note that a 'block' command doesn't end the execution.
Run this code. If you choose any of the 1st 4 options and then use the [Increment] button on
the realized dialog, it works. But if you choose the last option (nothing), that
button generates unassigned variable errors, even though its accesses a defined global variable.
I find it curious that noError/lastError do NOT trap this sort of error; code stops executing at the
offending line (i++ below), but noError() prevents it from being displayed in the DXL window
I'm not sure what to think about this. I guess we need more experiments on the difference between
a 'realized' and a 'shown' dialog, if indeed there are any differences.
*/
DB db
int i = 0
//****************
void SpecialEnding()
{ // Prompt user to make a Special Ending to the DXL, if any.
// Special ending is halt, error, or generating a run-time DXL error
string Options[] = {
"Show Sub-Dialog",
"Do 'Halt'?",
"Do 'Error'?",
"Generate DXL Error?",
"Nothing. This causes increment error"
}
int i
int Choice = query("End DXL with special..", Options)
if (Choice == 0) {print "Special Ending: show(db)\n";DB dbT = create(db, "Close Me");label(dbT, "Close this Dialog");show(dbT)}
elseif(Choice == 1) {print "Special Ending: halt\n"; halt}
elseif(Choice == 2) {print "Special Ending: error()\n"; error("End By 'error()'")}
elseif(Choice == 3) {print "Special Ending: i++\n"; Object o=null; Module m = module(o)} // Generate "null Object.." error
else {print "Special Ending: None\n"} // No special ending
} // end SpecialEnding()
void applyIncrement(DB dbXX)
{ lastError() // Offset the noError() below
print "Incrementing....\t"
i++
print ("Increment OK...\t")
}
//****************
void applyNoError(DB dbXX)
{ noError() // Attempt to trap the error
i++
string ErrMess = lastError()
if (!null ErrMess) //
then warningBox(ErrMess) // This line never runs because an error halts the DXL and is not trapped.
else print ("Increment OK...\t")
} // end applyNoError()
//****************
void BuildDialog()
{ db = centered("Special Ending")
apply(db, "Increment global variable", applyIncrement)
apply(db, "Increment, with noError()", applyNoError)
realize(db) // realized, not shown
}
// **** MAIN ****
BuildDialog()
SpecialEnding()
llandale - Wed Oct 26 10:07:14 EDT 2011 |